// 药房管理
<template comments>
  <div class="pharmacy">
    <TopManu :signOut="true" @handleQuit="$router.go(-1)"></TopManu>

    <div class="search">
      <div class="s1">
          <div class="put">
             <el-input v-model="params.keyword" placeholder="请输入名称"></el-input>
          </div>
          <div class="put">
          <el-select
            v-model="params.status"
            placeholder="状态"
            @change="searchB"
          >
            <el-option
              v-for="item in $baseBai['registeRsetting']['status']"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <el-button @click="searchB()">查询</el-button>
         <el-button type="success" @click="resetSearchB()">重置</el-button>
        <el-button @click="handleEdit('add')">新增</el-button>
      </div>
      <div class="selectBai">
      
     
      </div>
    </div>

    <div class="tablesB">
      <el-table v-loading="params.loading" :data="data" border>
        <el-table-column type="index" width="70" label="序号">
        </el-table-column>
        <template v-for="(item, index) in $baseBai['registeRsetting']['list']">
          <el-table-column
            :width="item.width"
            v-if="item.prop == 'status'"
            :prop="item.prop"
            :label="item.label"
            :key="index"
          >
            <template slot-scope="scope">
              
            
                <el-switch v-model="scope.row.status" @change="onchangeSwitch(scope.row)" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
               
            
            </template>
          </el-table-column>
            <el-table-column
            :width="item.width"
            v-else-if="item.prop == 'doctor.positional_title'"
            :prop="item.prop"
            :label="item.label"
            :key="index"
          >
            <template slot-scope="scope">
               
                <span v-if="scope.row.doctor">
                  
                    <span  v-for="(item,positional_title_index) in dict_positional" :key='positional_title_index'>
                              <span v-if="item.id==scope.row.doctor.positional_title">{{item.name}}</span>
                        </span>
                   </span>
                 
               
            
            </template>
          </el-table-column>
          <el-table-column
            v-else
            :width="item.width"
            :prop="item.prop"
            :label="item.label"
            :key="index + item"
          >
          </el-table-column>
        </template>
        <el-table-column label="操作" width="250" fixed="right">
          <template slot-scope="scope">
            <div>
              <el-button
                size="mini"
                type="danger"
                @click="handleEdit(scope.$index, scope.row, 1)"
                >修改</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-pagination
          class="fenye"
          :background="true"
          :current-page="params.page"
          :page-size="params.limit"
          layout="prev, pager, next"
          @current-change="handlePagination"
          :total="params.pageCount"
        >
        </el-pagination>
      </div>
    </div>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="Detail_Show"
      :destroy-on-close="true"
      v-if="Detail_Show"
      :close-on-click-modal="false"
      width="30%"
      :before-close="
        () => {
          this.Detail_Show = !this.Detail_Show;
        }
      "
    >
      <Save :dialogTitle="dialogTitle" :that="this"></Save>
    </el-dialog>
  </div>
</template>

<script>
let t;
import Save from "./common/save";
import TopManu from "@/components/TopMenu";
import { mapState, mapActions } from "vuex";

// getDict_dataKuFangList
export default {
  name:"registeRsetting",
  data() {
    return {
      Detail_Show: false,
      tableTitle: [],
      dialogTitle: "",
      params: {
        loading: false,
        tabIndex: "1",
        page: 1,
        limit: 10,
        status: "",
        keyword:'',
        pageCount: 0,
      },
      paramsSave: {
        id: "",
        user_id: "",
        register_fee: "",
        treat_fee: "",
        remark: "",
      },

      data: [],
    };
  },
  components: {
    TopManu,
    Save,
  },

  mounted() {
    t = this;
  t.getDictpositional(2)
   
  },
  computed: {
    ...mapState({
      doctorInfo: (state) => state.doctorInfo.doctorInfo,
      dict_positional: (state) => state.dictBai.dict_positional,
    }),
  },
  methods: {
    ...mapActions([
      "doctorInfo/getRegisterDoctorIndex",
       'dictBai/getDict_dataDictIndex',
      ]),
    getDictpositional(num){
     
     
        t['dictBai/getDict_dataDictIndex']({ group_id: num }).then((res) => {
          console.log("dict_positional",t.dict_positional)
          t.getList();
        });
    
    },
    resetSearchB(){
        this.params={
        loading: false,
        tabIndex: "1",
        page: 1,
        limit: 10,
        status: "",
        keyword:'',
        pageCount: 0,
      };
      this.getList()
    },
    onchangeSwitch(...item){

        let d={
          id:item[0].id,
          type:item[0].status?1:2
        }

       t['_API'].getregister_confFeeStatus(d).then(
          (res) => {
            if (res.code == 200) {

                     this.$message({
                      message:res.message,
                      type: 'success'
                     });
                //  t.getList()
            }
          }
        );
      //console.log("item",item)
    },
    handleEdit(...item) {
      console.log(item);
      if (item[0] == "add") {
        t.dialogTitle = "新增";
       
        t.paramsSave = {
          id: "",
          user_id: "",
           real_name:'',
          register_fee: "",
          treat_fee: "",
          remark: "",
        };
      } else {
        t.dialogTitle = "修改";
       

        t.paramsSave = {
          id: item[1].id,
          user_id: item[1].doctor.id,
          real_name:item[1].doctor.real_name,
          register_fee: item[1].register_fee,
          treat_fee: item[1].treat_fee,
          remark: item[1].remark,
        };
      }
    
    
              t.Detail_Show = !t.Detail_Show;
    
    },
    addSave(params) {
      let d = {
        register_fee: t.paramsSave.register_fee,
        treat_fee: t.paramsSave.treat_fee,
        remark: t.paramsSave.remark,
      };
      //  t.$message.error("请选择医生")
      if (t.paramsSave.id) {
        d.id =t.paramsSave.id ;
        
      } else {
        d.user_id = t.paramsSave.user_id;
         if(!d.user_id){
          return  t.$message.error("请选择医生")
        }
      }
       if(!d.register_fee){
        return  t.$message.error("请输入挂号金额")
      }else  if(!d.treat_fee){
        return  t.$message.error("请输入诊查金额")
      }



      this["_API"].getregister_confFeeSave(d).then((res) => {
        if (res.code == 200) {
          t.Detail_Show = !t.Detail_Show;
          t.params.page = 1;
          t.getList();
        }
      });
    },

    handcreate(num) {
      let url = "";
      console.log("num", num);
      switch (num) {
        case 1:
          url = "purchaseApply";
          break;
        case 2:
          url = "purchasePlan";
          break;
        case 3:
          url = "enterManage";
          break;
        case 4:
          url = "outManage";
          break;
        case 5:
          url = "drugCollar";
          break;
        case 6:
          url = "drugRetreat";
          break;
        case 7:
          url = "drugInspect";
          break;
        default:
          break;
      }
      this.$router.push({ name: url });
    },

    searchB() {
      t.params.page = 1;
      t.getList();
    },

    handlePagination(e) {
      t.params.page = e;
      t.getList();
    },
    getList() {
      let d = {
        limit: t.params.limit,
        page: t.params.page,
        status:t.params.status,
        keyword:t.params.keyword,
      };
      t.data = [];
      this.params.loading = true;
      this["_API"].getregister_confFeeIndex(d).then((res) => {
        this.params.loading = false;
        if (res.code == 200) {
          this.data = res.data.list.map(v=>{
            return {
              ...v,
              status:v.status===1?true:false,
            }
          });
          console.log("this.data",this.data)
          this.params.pageCount = res.data.count;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/ .el-tabs__nav {
  .el-tabs__item {
    border-bottom: 1px solid #e4e7ed;
  }
  .is-active {
    color: #02bf6b;
  }
  .el-tabs__item:hover {
    color: #02bf6b;
  }
}
.search {
  border: 1px solid #f2f2f2;
  margin: 10px 2%;
  padding: 20px;
  border-radius: 10px;
  .s1 {
    width: 700px;
    display: flex;
    .put{
      width: 300px;
      margin-right: 20px;
    }
    .el-input {
      margin-right: 10px;
    }
    button {
      margin-left: 20px;
      margin-bottom: 20px;
      background-color: #02bf6b;
      color: white;
    }
  }
  .selectBai {
    display: flex;
    > div {
      margin-right: 10px;
    }
  }
}

.tableMore {
  /deep/ .el-button--primary {
    color: black;
    background-color: initial;
    border-color: #e2e2e2;
  }
}
.tablesB,
.tabsB {
  margin: 20px 2% 0;
}

.fenye {
  text-align: right;
  margin-top: 20px;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #02bf6b;
}

/deep/ .el-dialog {
  width: 500px !important;
}
</style>